Completed
Push — master ( 597fc8...850b65 )
by Justin
02:13
created

module.exports   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
rs 9.6666
1
module.exports = function(GedcomX){
2
  
3
  var AtomCommon = require('./AtomCommon');
4
  
5
  /**
6
   * The Atom data formats provide a format for web content and metadata syndication.
7
   * The JSON data format is specific to GEDCOM X and is a translation to JSON from the XML.
8
   * 
9
   * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec}
10
   * @see {@link https://tools.ietf.org/html/rfc4287#section-4.1.1|RFC 4287}
11
   * 
12
   * @class
13
   * @extends AtomCommon
14
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
15
   */ 
16
  var AtomFeed = function(json){
17
    
18
    // Protect against forgetting the new keyword when calling the constructor
19
    if(!(this instanceof AtomFeed)){
20
      return new AtomFeed(json);
21
    }
22
    
23
    // If the given object is already an instance then just return it. DON'T copy it.
24
    if(AtomFeed.isInstance(json)){
25
      return json;
26
    }
27
    
28
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  };
30
  
31
  AtomFeed.prototype = Object.create(AtomCommon.prototype);
32
33
  AtomFeed._gedxClass = AtomFeed.prototype._gedxClass = 'GedcomX.AtomFeed';
34
  
35
  AtomFeed.jsonProps = [
36
    'authors', 
37
    'contributors', 
38
    'categories', 
39
    'generator', 
40
    'icon', 
41
    'id', 
42
    'results', 
43
    'index', 
44
    'links', 
45
    'logo', 
46
    'rights', 
47
    'subtitle', 
48
    'title', 
49
    'updated', 
50
    'entries', 
51
    'facets', 
52
    'searchInfo' 
53
  ];
54
  
55
  /**
56
   * Check whether the given object is an instance of this class.
57
   * 
58
   * @param {Object} obj
59
   * @returns {Boolean}
60
   */
61
  AtomFeed.isInstance = function(obj){
62
    return GedcomX.utils.isInstance(obj, this._gedxClass);
63
  };
64
  
65
  /**
66
   * Initialize from JSON
67
   * 
68
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
69
   * @return AtomFeed this
70
   */
71
  AtomFeed.prototype.init = function(json){
72
    
73
    AtomCommon.prototype.init.call(this, json);
74
    
75
    if(json){
76
      this.setAuthors(json.authors); 
77
      this.setContributors(json.contributors); 
78
      this.setCategories(json.categories); 
79
      this.setGenerator(json.generator); 
80
      this.setIcon(json.icon); 
81
      this.setId(json.id); 
82
      this.setResults(json.results); 
83
      this.setIndex(json.index); 
84
      this.setLinks(json.links); 
85
      this.setLogo(json.logo); 
86
      this.setRights(json.rights); 
87
      this.setSubtitle(json.subtitle); 
88
      this.setTitle(json.title); 
89
      this.setUpdated(json.updated); 
90
      this.setEntries(json.entries); 
91
      this.setFacets(json.facets); 
92
      this.setSearchInfo(json.searchInfo); 
93
    }
94
    return this;
95
  };
96
  
97
  /**
98
   * Get the authors
99
   * 
100
   * @return {AtomPerson[]}
101
   */
102
  AtomFeed.prototype.getAuthors = function(){
103
    return this.authors || [];
104
  };
105
  
106
  /**
107
   * Set the authors
108
   * 
109
   * @param {AtomPerson[]} authors
110
   * @returns {AtomFeed} this
111
   */
112
  AtomFeed.prototype.setAuthors = function(authors){
113
    return this._setArray(authors, 'authors', 'addAuthor');
114
  };
115
  
116
  /**
117
   * Add a author
118
   * 
119
   * @param {AtomPerson} author
120
   * @returns {AtomFeed} this
121
   */
122
  AtomFeed.prototype.addAuthor = function(author){
123
    return this._arrayPush(author, 'authors', GedcomX.AtomPerson);
124
  };    
125
  
126
  /**
127
   * Get the contributors
128
   * 
129
   * @return {AtomPerson[]}
130
   */
131
  AtomFeed.prototype.getContributors = function(){
132
    return this.contributors || [];
133
  };
134
  
135
  /**
136
   * Set the contributors
137
   * 
138
   * @param {AtomPerson[]} contributors
139
   * @returns {AtomFeed} this
140
   */
141
  AtomFeed.prototype.setContributors = function(contributors){
142
    return this._setArray(contributors, 'contributors', 'addContributor');
143
  };
144
  
145
  /**
146
   * Add a contributor
147
   * 
148
   * @param {AtomPerson} contributor
149
   * @returns {AtomFeed} this
150
   */
151
  AtomFeed.prototype.addContributor = function(contributor){
152
    return this._arrayPush(contributor, 'contributors', GedcomX.AtomPerson);
153
  };    
154
  
155
  /**
156
   * Get the categories
157
   * 
158
   * @return {AtomCategory[]}
159
   */
160
  AtomFeed.prototype.getCategories = function(){
161
    return this.categories || [];
162
  };
163
  
164
  /**
165
   * Set the categories
166
   * 
167
   * @param {AtomCategory[]} categories
168
   * @returns {AtomFeed} this
169
   */
170
  AtomFeed.prototype.setCategories = function(categories){
171
    return this._setArray(categories, 'categories', 'addCategorie');
172
  };
173
  
174
  /**
175
   * Add a categorie
176
   * 
177
   * @param {AtomCategory} categorie
178
   * @returns {AtomFeed} this
179
   */
180
  AtomFeed.prototype.addCategorie = function(categorie){
181
    return this._arrayPush(categorie, 'categories', GedcomX.AtomCategory);
182
  };    
183
  
184
  /**
185
   * Get the generator
186
   * 
187
   * @returns {AtomGenerator} generator
188
   */
189
  AtomFeed.prototype.getGenerator = function(){
190
    return this.generator;
191
  };
192
  
193
  /**
194
   * Set the generator
195
   * 
196
   * @param {AtomGenerator} generator
197
   * @returns {AtomFeed} this
198
   */
199
  AtomFeed.prototype.setGenerator = function(generator){
200
    if(generator){
201
      this.generator = GedcomX.AtomGenerator(generator);
202
    }
203
    return this;
204
  };    
205
  
206
  /**
207
   * Get the icon
208
   * 
209
   * @returns {String} icon
210
   */
211
  AtomFeed.prototype.getIcon = function(){
212
    return this.icon;
213
  };
214
  
215
  /**
216
   * Set the icon
217
   * 
218
   * @param {String} icon
219
   * @returns {AtomFeed} this
220
   */
221
  AtomFeed.prototype.setIcon = function(icon){
222
    this.icon = icon;
223
    return this;
224
  };        
225
  
226
  /**
227
   * Get the id
228
   * 
229
   * @returns {String} id
230
   */
231
  AtomFeed.prototype.getId = function(){
232
    return this.id;
233
  };
234
  
235
  /**
236
   * Set the id
237
   * 
238
   * @param {String} id
239
   * @returns {AtomFeed} this
240
   */
241
  AtomFeed.prototype.setId = function(id){
242
    this.id = id;
243
    return this;
244
  };        
245
  
246
  /**
247
   * Get the results
248
   * 
249
   * @returns {Integer} results
250
   */
251
  AtomFeed.prototype.getResults = function(){
252
    return this.results;
253
  };
254
  
255
  /**
256
   * Set the results
257
   * 
258
   * @param {Integer} results
259
   * @returns {AtomFeed} this
260
   */
261
  AtomFeed.prototype.setResults = function(results){
262
    this.results = results;
263
    return this;
264
  };        
265
  
266
  /**
267
   * Get the index
268
   * 
269
   * @returns {Integer} index
270
   */
271
  AtomFeed.prototype.getIndex = function(){
272
    return this.index;
273
  };
274
  
275
  /**
276
   * Set the index
277
   * 
278
   * @param {Integer} index
279
   * @returns {AtomFeed} this
280
   */
281
  AtomFeed.prototype.setIndex = function(index){
282
    this.index = index;
283
    return this;
284
  };        
285
  
286
  /**
287
   * Set the links
288
   * 
289
   * @param {Links} links
290
   * @return {AtomFeed} this
291
   */
292
  AtomFeed.prototype.setLinks = function(links){
293
    if(links){
294
      this.links = GedcomX.Links(links);
295
    }
296
    return this;
297
  };
298
  
299
  /**
300
   * Add a link
301
   * 
302
   * @param {Link} link
303
   * @return {AtomFeed} this
304
   */
305
  AtomFeed.prototype.addLink = function(link){
306
    if(link){
307
      if(!this.links){
308
        this.links = GedcomX.Links();
309
      }
310
      this.links.addLink(link);
311
    }
312
    return this;
313
  };
314
  
315
  /**
316
   * Get the links
317
   * 
318
   * @return {Link[]}
319
   */
320
  AtomFeed.prototype.getLinks = function(){
321
    return this.links ? this.links.getLinks() : [];
322
  };
323
  
324
  /**
325
   * Get a link
326
   * 
327
   * @param {String} rel
328
   * @return {Link}
329
   */
330
  AtomFeed.prototype.getLink = function(rel){
331
    if(this.links){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.links is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
332
      return this.links.getLink(rel);
333
    }
334
  };
335
  
336
  /**
337
   * Get the logo
338
   * 
339
   * @returns {String} logo
340
   */
341
  AtomFeed.prototype.getLogo = function(){
342
    return this.logo;
343
  };
344
  
345
  /**
346
   * Set the logo
347
   * 
348
   * @param {String} logo
349
   * @returns {AtomFeed} this
350
   */
351
  AtomFeed.prototype.setLogo = function(logo){
352
    this.logo = logo;
353
    return this;
354
  };        
355
  
356
  /**
357
   * Get the rights
358
   * 
359
   * @returns {String} rights
360
   */
361
  AtomFeed.prototype.getRights = function(){
362
    return this.rights;
363
  };
364
  
365
  /**
366
   * Set the rights
367
   * 
368
   * @param {String} rights
369
   * @returns {AtomFeed} this
370
   */
371
  AtomFeed.prototype.setRights = function(rights){
372
    this.rights = rights;
373
    return this;
374
  };        
375
  
376
  /**
377
   * Get the subtitle
378
   * 
379
   * @returns {String} subtitle
380
   */
381
  AtomFeed.prototype.getSubtitle = function(){
382
    return this.subtitle;
383
  };
384
  
385
  /**
386
   * Set the subtitle
387
   * 
388
   * @param {String} subtitle
389
   * @returns {AtomFeed} this
390
   */
391
  AtomFeed.prototype.setSubtitle = function(subtitle){
392
    this.subtitle = subtitle;
393
    return this;
394
  };        
395
  
396
  /**
397
   * Get the title
398
   * 
399
   * @returns {String} title
400
   */
401
  AtomFeed.prototype.getTitle = function(){
402
    return this.title;
403
  };
404
  
405
  /**
406
   * Set the title
407
   * 
408
   * @param {String} title
409
   * @returns {AtomFeed} this
410
   */
411
  AtomFeed.prototype.setTitle = function(title){
412
    this.title = title;
413
    return this;
414
  };        
415
  
416
  /**
417
   * Get the updated
418
   * 
419
   * @returns {Date} updated
420
   */
421
  AtomFeed.prototype.getUpdated = function(){
422
    return this.updated;
423
  };
424
  
425
  /**
426
   * Set the updated
427
   * 
428
   * @param {Date|Integer} updated
429
   * @returns {AtomFeed} this
430
   */
431
  AtomFeed.prototype.setUpdated = function(updated){
432
    if(updated){
433
      this.updated = new Date(updated);
434
    }
435
    return this;
436
  };        
437
  
438
  /**
439
   * Get the entries
440
   * 
441
   * @return {AtomEntry[]}
442
   */
443
  AtomFeed.prototype.getEntries = function(){
444
    return this.entries || [];
445
  };
446
  
447
  /**
448
   * Set the entries
449
   * 
450
   * @param {AtomEntry[]} entries
451
   * @returns {AtomFeed} this
452
   */
453
  AtomFeed.prototype.setEntries = function(entries){
454
    return this._setArray(entries, 'entries', 'addEntry');
455
  };
456
  
457
  /**
458
   * Add an entry
459
   * 
460
   * @param {AtomEntry} entry
461
   * @returns {AtomFeed} this
462
   */
463
  AtomFeed.prototype.addEntry = function(entry){
464
    return this._arrayPush(entry, 'entries', GedcomX.AtomEntry);
465
  };    
466
  
467
  /**
468
   * Get the facets
469
   * 
470
   * @return {Field[]}
471
   */
472
  AtomFeed.prototype.getFacets = function(){
473
    return this.facets || [];
474
  };
475
  
476
  /**
477
   * Set the facets
478
   * 
479
   * @param {Field[]} facets
480
   * @returns {AtomFeed} this
481
   */
482
  AtomFeed.prototype.setFacets = function(facets){
483
    return this._setArray(facets, 'facets', 'addFacet');
484
  };
485
  
486
  /**
487
   * Add a facet
488
   * 
489
   * @param {Field} facet
490
   * @returns {AtomFeed} this
491
   */
492
  AtomFeed.prototype.addFacet = function(facet){
493
    return this._arrayPush(facet, 'facets', GedcomX.Field);
494
  };    
495
  
496
  /**
497
   * Get the searchInfo
498
   * 
499
   * @return {SearchInfo[]}
500
   */
501
  AtomFeed.prototype.getSearchInfo = function(){
502
    return this.searchInfo || [];
503
  };
504
  
505
  /**
506
   * Set the searchInfo
507
   * 
508
   * @param {SearchInfo[]} searchInfo
509
   * @returns {AtomFeed} this
510
   */
511
  AtomFeed.prototype.setSearchInfo = function(searchInfo){
512
    return this._setArray(searchInfo, 'searchInfo', 'addSearchInfo');
513
  };
514
  
515
  /**
516
   * Add a searchInfo
517
   * 
518
   * @param {SearchInfo} searchInfo
519
   * @returns {AtomFeed} this
520
   */
521
  AtomFeed.prototype.addSearchInfo = function(searchInfo){
522
    return this._arrayPush(searchInfo, 'searchInfo', GedcomX.SearchInfo);
523
  };    
524
  
525
  /**
526
   * Export the object as JSON
527
   * 
528
   * @return {Object} JSON object
529
   */
530
  AtomFeed.prototype.toJSON = function(){
531
    return this._toJSON(AtomCommon, AtomFeed.jsonProps);
532
  };
533
  
534
  GedcomX.AtomFeed = AtomFeed;
535
  
536
};